package com.osexp.model;

import java.util.List;

public class Disk implements paraConstants{
	mappingReader nfr=null;
	List<mapping> mList=null;
	int currDiskAddress;	
	
	public Disk() {
		super();
		nfr=new mappingReader();
		mList=nfr.formatRead("mapping.txt");
		currDiskAddress=0;
	}

	public double findTime(int iLogicalAddress) {
		int iDiskAddress=-1;
		int time=0;
		for(mapping m:mList){
			if (m.getiLogicalAddress()==iLogicalAddress){
				iDiskAddress=m.getiDiskAddress();
				break;
			}			
		}
		if(iDiskAddress==-1){
			System.out.println("爆炸at"+iLogicalAddress+"==================================================");
		}
		time+=Math.abs(getTrack(iDiskAddress)-getTrack(currDiskAddress))*iSeekTime;
		time+=Math.abs(getSector(iDiskAddress)-getSector(currDiskAddress))*iRotationalTime;
		time+=iTransferTime;		
		System.out.println("timeused=================="+time);
		return time;	
	}
	
	private int getTrack(int iDiskAddress) {		
		return iDiskAddress/32;		
	}
	
	private int getSector(int iDiskAddress) {		
		return iDiskAddress%32;		
	}
	public static void main(String[] args) {
		Disk disk=new Disk();
		System.out.println(disk.findTime(4679));
	}

}
